﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace MillerApp.UserControls
{
    [
    ProvideProperty("MappingProperty", typeof(Control)),
    ProvideProperty("MappingControlProperty", typeof(Control)),
    ]
    public partial class DataMappingContainer : Component, IExtenderProvider
    {
        public DataMappingContainer()
        {
            InitializeComponent();
        }

        public DataMappingContainer(IContainer container)
        {
            container.Add(this);
            InitializeComponent();
        }

        public bool CanExtend(object extendee)
        {
            if (extendee is Form)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        #region
        private Dictionary<Control, string> dataMappingClasses = new Dictionary<Control, string>();
        private Dictionary<Control, string> dataMappingProperties = new Dictionary<Control, string>();
        private Dictionary<Control, string> dataMappingControlProperties = new Dictionary<Control, string>();

        [DefaultValue(typeof(string))]
        public string GetMappingProperty(Control Ctrl)
        {
            if (this.dataMappingProperties.ContainsKey(Ctrl))
            {
                return dataMappingProperties[Ctrl];
            }
            else
            {
                return string.Empty;
            }
        }

        public void SetMappingProperty(Control Ctrl, string mappingClass)
        {
            if (this.dataMappingProperties.ContainsKey(Ctrl))
            {
                this.dataMappingProperties[Ctrl] = mappingClass;
            }
            else
            {
                this.dataMappingProperties.Add(Ctrl, mappingClass);
            }
        }

        [DefaultValue(typeof(string))]
        public string GetMappingControlProperty(Control Ctrl)
        {
            if (this.dataMappingControlProperties.ContainsKey(Ctrl))
            {
                return dataMappingControlProperties[Ctrl];
            }
            else
            {
                return "Text";
            }
        }

        public void SetMappingControlProperty(Control Ctrl, string mappingClass)
        {
            if (this.dataMappingControlProperties.ContainsKey(Ctrl))
            {
                this.dataMappingControlProperties[Ctrl] = mappingClass;
            }
            else
            {
                this.dataMappingControlProperties.Add(Ctrl, mappingClass);
            }
        }

        public override string ToString()
        {
            return "StyleContainer";
        }


        #endregion
    }
}
